home *** CD-ROM | disk | FTP | other *** search
/ Mastering Microsoft Visual Basic 5 / Mastering Microsoft Visual Basic 5.ISO / media / ch02 / v02d005.cc < prev    next >
Text File  |  1997-01-24  |  4KB  |  38 lines

  1. 0, In this demonstration we will look at using the data control to view and edit information in the database.
  2. 7, The data control allows you to easily create database front ends because it handles the majority of the work associated with creating a database application, such as opening and editing information.
  3. 18, Let's go ahead and look at creating a simple database front end.
  4. 21, The first thing we need to do is just simply draw a data control on the form.
  5. 25, So we'll click the data control in the toolbox and draw it on the form.
  6. 29, Then we need to set two properties of the data control that tell it which database information we want to work with.
  7. 35,  The first is the DatabaseName.
  8. 38,  The database we'll use here is the Northwind database that comes with Microsoft Visual Basic.
  9. 43,  The next property is the RecordSource property.
  10. 46,  The RecordSource property defines which set of records in the database we'll be working with.
  11. 51,  We could either type a SQL query here, or if I just click this drop list we'll get a list of all the tables in the database.
  12. 59,  I'll go ahead and select the Products table.
  13. 62, The next thing we need to do is add fields to the form that the user actually interacts with when editing the database information.
  14. 68,  Those fields then in turn use the data control to communicate with the database.
  15. 73,  The first field I'll put on is a label control.
  16. 76,  Now label control let us view database information but not edit it.
  17. 81,  Next, I'll place a text box control and the text box control let us view and edit information.
  18. 86,  And finally, I'll place a check box control on the form which will let us view and edit Boolean information.
  19. 93, Now, we need to set some properties of these controls.
  20. 96,  Go ahead and select the label control.
  21. 98,  And the first property that we need to set is the DataSource property.
  22. 103,  The DataSource is actually the data control that this field will use to communicate with the database.
  23. 108,  We'll go ahead and select Data1and then the DataField is the actual field that we want to be viewed in edit and/or edited in this control.
  24. 116,  In this case we'll select ProductID.
  25. 119,  We'll do the same with the text box--again the DataSource is Data1.
  26. 123,  And this time the DataField we'll choose product name.
  27. 127,  And then finally we'll do the check box here and again the DataSource will be Data1.
  28. 132,  And this time the DataField will be a field named discontinued, which is a yes/no field in this Access database.
  29. 139, After we've set all the properties of the controls, we can go ahead and run this application.
  30. 145,  Notice now that I'm viewing actual database information, and as I scroll through each of the records in the database we'll see that information change.
  31. 154,  I can also edit this information.
  32. 156,  So if I want to change something in one of the records, I simply go to the text box here and type something new in.
  33. 163,  And I can also change the yes/no field by simply selecting the check box.
  34. 167,  Now notice I move to another record and then come back to that record that the information in the database has actually been updated.
  35. 175,  I can also navigate to the beginning of the database by clicking this button or the end of the database by clicking this button.
  36. 183,  We'll go ahead and end this application.
  37. 186, So what you've seen in this demonstration is that the data control provides a very easy way to create database front-ends.
  38. 193, END